# -*-coding=utf8-*-
from xpinyin import Pinyin
import os
import sys

resume_rootdir = '/home/space/Documents/train_data/20210714/6.22-7387/2021.6.16'


def rename():
    print(u'重命名开始！')
    pin = Pinyin()
    llist = os.listdir(resume_rootdir)
    for i in range(0, len(llist)):
        print(u'现在进行第{}个'.format(i))
        resume = os.path.join(resume_rootdir, llist[i])
        print(resume)


        print(u'开始处理  {}'.format(resume))
        pinyin_name = pin.get_pinyin(resume.encode('utf-8').decode('utf-8'), "")
        print(u'{} 新名字是:{}'.format(resume, pinyin_name))
        Newdir = os.path.join(resume_rootdir, pinyin_name);  # 新的文件路径
        os.rename(resume, Newdir)  # 重命名
    print(u'重命名结束！')

if __name__ == "__main__":
    rename()
